package com.wiscamp.ninechapters.problems.infrastructure.mappers.exams;

import com.wiscamp.ninechapters.problems.infrastructure.po.exams.PaperPartView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

/**
 * 试卷部分数据访问对象
 *
 * @author yifeng
 */
@Repository
public interface PaperPartViewMapper extends JpaRepository<PaperPartView, Long>, JpaSpecificationExecutor<PaperPartView> {
    /**
     * 通过考试编号和试卷部分编号获取试卷部分
     *
     * @param examId
     * @param partId
     * @return
     */
    @Query(value = "select p from PaperPartView p where p.examId = :examId and p.partId = :partId order by p.version asc, p.partIndex asc")
    PaperPartView findByExamAndPart(long examId, long partId);

    /**
     * 通过考试编号获取试卷部分列表
     *
     * @param examId
     * @return
     */
    @Query(value = "select p from PaperPartView p where p.examId = :examId order by p.version asc, p.partIndex asc")
    Collection<PaperPartView> findListByExam(long examId);
}